<!-- 自提点核销优惠券 -->
<template>
  <div id="writeOffCodePage">
    <c-title :hide="false" text="优惠券核销"></c-title>
    <div style="margin:1rem 0;">
      <van-cell-group inset>
        <van-cell v-for="(item,index) in list" :key="index" :title="item.name" :value="item.value"/>
      </van-cell-group>
    </div>
    <div style="margin: 1rem;">
      <van-button type="primary" round block v-if="!used" @click="onClick">确认核销</van-button>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      list: [],
      used: 1
    };
  },

  created() {
    this.getData();
  },

  components: {},

  computed: {},

  mounted() {},

  methods: {
    async getData() {
      let _parame = {
        id: this.$route.params.id,
        coupon_id: this.$route.params.coupon_id,
        check: this.$route.query.check
      };
      let { msg, result, data } = await $http.get('plugin.package-deliver-write-off.frontend.controllers.write-off.write-off-page', _parame, ".");
      if (result == 0) {
        return this.$toast(msg);
      }
      this.list = data.info;
      this.used = data.used;
      if(this.used) {
        this.$dialog.alert({
          message: '该优惠券已核销过',
        });
      }
    },
    async onClick(){
      let _parame = {
        id: this.$route.params.id,
        coupon_id: this.$route.params.coupon_id,
        check: this.$route.query.check
      };
      let { msg } = await $http.get('plugin.package-deliver-write-off.frontend.controllers.write-off.write-off', _parame, ".");
      this.$dialog.alert({
        message: msg,
      }).then(() => {
        // on close
        this.getData();
      });
    }
  }
};

</script>
<style lang='scss' rel='stylesheet/scss' scoped>
#writeOffCodePage{
  text-align: left;
}
</style>